package com.example.zhc36.fragment.apadter;


import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import com.example.zhc36.fragment.R;

import com.example.zhc36.fragment.bean.userbean;
import com.example.zhc36.fragment.utils.pic.GlideApp;

import java.util.List;

public class Rvmsgadapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    private List<userbean> list;

    public Rvmsgadapter(List<userbean> list) {


        this.list = list;
    }





    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        LayoutInflater from = LayoutInflater.from(parent.getContext());
        View view = from.inflate(R.layout.msgitm_main, parent, false);
        ViewHolder holder = new ViewHolder(view);

        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
             ViewHolder vh= (ViewHolder) holder;
        userbean userbean = list.get(position);
        vh.sedate(userbean);


    }


    @Override
    public int getItemCount() {
        return list.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
       private ImageView img;
        private TextView tv;


        public ViewHolder(View itemView) {
            super(itemView);
            img=itemView.findViewById(R.id.img);
            tv=itemView.findViewById(R.id.tv);

        }
        public void sedate(userbean bean){

            GlideApp.with(img.getContext()).load(bean.getHeadUrl()).into(img);
            tv.setText(bean.getName());
        }
    }
}
